require('../../assets/css/index.less')
require('./course-details.less')
require('../../assets/js/property')
require('../../assets/font/font_3852666_7r0dooui378/iconfont.css')
const request = require('../../intils/reques')
// 定义api地址
const url = 'http://fitness.h5.itsource.cn:3701'

window.onload = () => {
    const courseId = location.search.split('=')[1]
    // 获取课程数据
    function getData() {
        request.get('/api/train/courseDetail', {
            params: {
                id: courseId
            }
        }).then(res => {
            let { errno, data } = res.data
            console.log(res.data);
           if(errno===0){
            localStorage.setItem('fragments',JSON.stringify(data.fragments))
            $('.video').src=url+data.fragments[0].videoUrl
            renderData(data)
           }
        })





    }

    getData()


    // 渲染函数
    function renderData(data){
        $('#title-1').textContent=data.name
        $('#calorie').textContent=data.calorie
        $('#time').textContent=data.time
        $('#peoplenum').textContent=data.peoplenum+'人练过'
        $('#userimg').src=url+data.imgurl
        $('#miaoshu').textContent=data.desc
        $('#frequency').textContent='每周'+data.frequency+'次'
        $('#instrument').textContent=data.instrument



    }
    // 点击箭头返回上一页
    $('.icon-shangyiyehoutuifanhui').addEventListener('click',()=>{
        history.back(1)
    })
    // 点击播放按钮
    $('.icon-bofang').addEventListener('click',()=>{
        $('.mask').style.display='none'
        $('.pause').style.display='none'
        $('.video').play()


    })
















}